/**
 * SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
 * SPDX-License-Identifier: Mulan PSL v2
 */
import getPlatformInfo from './platform_info';
import { getStorage } from 'src/util/local_storage';
import { USER_ID, USER_ROLE } from 'src/home/mod_common/const';
import { IS_ADMIN, USERS_ID} from 'src/vuex/mutation_types';



/* eslint-disable */
function storeStorage (store) {
    // let token = getStorage(CSRF_TOKEN);
    // store.commit(token);

    let userID = getStorage(USER_ID);
    store.commit(USERS_ID, userID);

    let isAdmin = !!getStorage(USER_ROLE);
    store.commit(IS_ADMIN, isAdmin);
}

export default function beforeInit (callback, store) {
    let p = Promise.all([
        getPlatformInfo(store),

        new Promise((resolve) => {
            storeStorage(store);

            resolve();
        })
    ]);

    p.then(() => {
        callback();
    }).catch(msg => {
        window.alert(msg);
    });
}
